package fileinn

// 文件客栈(临时文件/目录暂存)
import (
	"os"
	"time"
)

// 配置变量
var (
	CycleTime   time.Duration
	ExpiredTime time.Duration
	SavePath    string
	MaxSize     uint
	DBBucket    []byte
	FileName    string
)

func init() {
	CycleTime = time.Minute * 1
	ExpiredTime = time.Minute * 20
	SavePath = "./temp"
	FileName = "index.db"
	DBBucket = []byte("files")
	MaxSize = 1024 * 1024 * 1024 * 100

	exist, err := PathExists(SavePath)
	if err != nil {
		panic(err)
	}

	if !exist {
		err := os.Mkdir(SavePath, os.ModePerm)
		if err != nil {
			panic(err)
		}
	}
}

// SetExpiredTime 设置默认过期时间
func SetExpiredTime(t time.Duration) {
	ExpiredTime = t
}

// SetSavePath 设置保存路径
func SetSavePath(p string) {
	SavePath = p
}

// SetMaxSize 设置最大文件尺寸
func SetMaxSize(s uint) {
	MaxSize = s
}

// SetCycleTime 设置检测周期
func SetCycleTime(t time.Duration) {
	CycleTime = t
}
